package ppa.application.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class GameWindow extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JButton btLoad;
	private JButton btValid;
	private JButton btSave;
	private JButton btCreate;
	private JButton btReInit;
	
	private JTextArea taGame;
	private JTextField tfInput;

	public GameWindow() {
		super();

		buildWindow();
	}

	public JButton getBtLoad() {
		return btLoad;
	}

	public JButton getBtValid() {
		return btValid;
	}

	public JButton getBtSave() {
		return btSave;
	}
	
	public JButton getBtCreate() {
		return btCreate;
	}

	public JTextArea getTaGame() {
		return taGame;
	}

	public JTextField getTfInput() {
		return tfInput;
	}

	private void buildWindow() {
		setTitle("XML RPG Game Loader");
		setSize(650, 550);
		setLocationRelativeTo(null);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setContentPane(buildContentPane());
	}

	public void addTexttoTextArea(String text) {
		taGame.setText(taGame.getText() + "\n" + text);
	}

	private JPanel buildContentPane() {
		JPanel panel = new JPanel();
		BorderLayout bl = new BorderLayout(5, 10);
		panel.setLayout(bl);
		panel.setBackground(Color.BLACK);

		taGame = new JTextArea();
		taGame.setEditable(false);
		JScrollPane scrollPane = new JScrollPane(taGame);
		scrollPane.setVerticalScrollBarPolicy(
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		panel.add(scrollPane, BorderLayout.CENTER);
		

		/*
		 * Panel North
		 */
		JPanel pNorth = new JPanel();
		pNorth.setLayout(new FlowLayout());

		btLoad = new JButton("Load game");
		btSave = new JButton("Save Game");
		btCreate = new JButton("Create Game");
		btReInit = new JButton("Reinit Game");

		pNorth.add(btSave);
		pNorth.add(btLoad);
		pNorth.add(btCreate);
		pNorth.add(btReInit);
		
		JPanel pSouth = new JPanel();
		pSouth.setLayout(new FlowLayout());

		tfInput = new JTextField();
		tfInput.setColumns(20);

		btValid = new JButton("Go !");

		pSouth.add(tfInput);
		pSouth.add(btValid);

		panel.add(pNorth, BorderLayout.NORTH);
		panel.add(pSouth, BorderLayout.SOUTH);

		return panel;
	}

	public JButton getBtReInit() {
		return btReInit;
	}
}
